<?php

namespace app\common\validate\User;

//引入底层的验证器类
use think\Validate;

/**
 * 用户验证器
 */
class User extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        //email字段，必须是必填、邮箱类型、唯一的对照user表
        'email' => 'require|email|unique:user',
        'password' => 'require', //必填
        'salt' => 'require', //必填
        'nickname' => 'require', //必填
        'sex' => 'number|in:0,1,2',  //给字段设置范围
        'point' => 'number|egt:0',  //给字段设置 >= 0
        'vip' => 'number|in:0,1',  //给字段设置范围
        'auth' => 'number|in:0,1',  //给字段设置范围
        'openid' => 'unique:user', //openid必须是唯一的
    ];

    /**
     * 提示消息
     */
    protected $message = [
        'email.require' => '邮箱必填',
        'email.email' => '邮箱格式不对',
        'email.unique' => '邮箱已存在，请重新输入',
        'password.require'  => '密码必填',
        'nickname.require'  => '昵称必填',
        'salt.require'      => '密码盐必填',
        'sex.require'    => '性别必填',
        'point.number'    => '积分必须是个数字',
        'point.egt'    => '积分值必须是大于等于0',
    ];
    
    /**
     * 验证场景
     */
    protected $scene = [

        //修改个人资料
        'profile' => ['email', 'nickname', 'sex', 'auth'],
        'check' => ['openid'],
        'save' => ['email','openid','password','salt']
    ];
}